const { getshop, update, shopperuserupdate } = require('../..//service/main/getshop')

module.exports = {
    async shopget(ctx, next) {
        const { offset, limit, seach } = ctx.request.query
        let { id, titname, pername, phone, time, address, status } = JSON.parse(seach)
        console.log(offset, limit, id, titname, pername, phone, time, address, status)
        const { rows, count } = await getshop(offset, limit, id, titname, pername, phone, time, address, status)
        ctx.body = {
            code: 200,
            msg: '查询成功',
            data: {
                rows, count
            }
        }
    },
    async shopsucc(ctx, next) {
        const { id, userid } = ctx.request.body
        const rudata = await update(id, { status: 1 })
        await shopperuserupdate(userid, { kai: 2 })
        if (rudata) {
            return ctx.body = {
                code: 200,
                msg: '修改成功'
            }
        }
        ctx.body = {
            code: 0,
            msg: '修改失败'
        }
    },
    async shopclose(ctx, next) {
        const { id, userid } = ctx.request.body
        const rudata = await update(id, { status: 2 })
        await shopperuserupdate(userid, { kai: 3 })

        if (rudata) {
            return ctx.body = {
                code: 200,
                msg: '修改成功'
            }
        }
        ctx.body = {
            code: 0,
            msg: '修改失败'
        }
    },
    async shopout(ctx, next) {
        const { id } = ctx.request.body
        const rudata = await update(id, { status: 4 })
        if (rudata) {
            return ctx.body = {
                code: 200,
                msg: '修改成功'
            }
        }
        ctx.body = {
            code: 0,
            msg: '修改失败'
        }
    }
}